package cn.quang.search.admin.enums;

import java.util.Arrays;
import java.util.Objects;

public enum PresetConditionValueTypeEnum {
    SYSTEM_VAR(1, "系统变量"),
    CONTEXT(2, "上下文"),
    INPUT(3, "输入");


    private final int code;
    private final String name;

    PresetConditionValueTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static PresetConditionValueTypeEnum getByCode(int type) {
        return Objects.requireNonNull(Arrays.stream(values())
                .filter(input -> input.getCode() == type).findAny().orElse(null));
    }

    public static String getNameByCode(int type) {
        return Objects.requireNonNull(Arrays.stream(values())
                .filter(input -> input.getCode() == type).findAny().orElse(null)).getName();
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
